<?php

namespace App\Dao;

use App\Model\BBillsModel;
use Illuminate\Support\Facades\DB;

class TaskDao extends BaseDao
{


    public static function everyDayPrice()
    {

        $dateTime = strtotime(date('Y-m-d'));


        BusinessesDao::builder_query(['orders'=>1])
            ->where('time','<',$dateTime)
            ->where('rate_price',0)
            ->update(['time'=>$dateTime]);
        //分钱给所有人
        $shopModelDatas = BusinessesDao::builder_query(['orders'=>1])
            ->where('time','<',$dateTime)
            ->where('rate_price','>',0)
            ->orderBy('time')
            ->orderBy('businesses_id')
            ->limit(1);

        if($shopModelDatas->exists()){
            $data = $shopModelDatas->first()->toArray();
            $listsCountU = LineUpPriceDao::builder_query([
                'shop_id'=>$data['businesses_id'],
                'status'=>0
            ])->pluck('user_id');
            if(count($listsCountU) > 0) {
                $pricesMoney = bcdiv($data['rate_price'], count($listsCountU), 2);

                if ($pricesMoney > 0.01) {
                    BusinessesDao::everyPriceGive($pricesMoney, $data['businesses_id']);
                }
            }
            //每个人给钱
            BusinessesDao::builder_query(['businesses_id'=>$data['businesses_id']])->update([
                'time'=>$dateTime
            ]);

        }
    }
}
